# TABLE 2
# Authors: Mark Kayser & Kasia Nalewajko
# First created: Feb 6, 2023
# Replicated: Nov 18, 2025

rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("estimatr")) install.packages("estimatr")
if (!require("modelsummary")) install.packages("modelsummary")

# LOAD DATA ---------------------------------------------------------------

setwd("set/path/to/folder")

load(file = "./01 data/02 generated data/study2/02results_fullsample_clean.Rda")

# RUN MODEL ----

# PO supporters only 

temp <- results %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check == 3) %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check == 3) %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))
